package io.gitee.chearnee.fw.sidecar;

import io.gitee.chearnee.fw.sidecar.action.BootstrapActionHelper;
import io.gitee.chearnee.fw.sidecar.application.ApplicationRegister;
import io.gitee.chearnee.fw.sidecar.application.ServiceInfo;
import io.gitee.chearnee.fw.sidecar.client.ClientHelper;
import io.gitee.chearnee.fw.sidecar.client.PlatClient;
import io.gitee.chearnee.fw.sidecar.workshop.ActionConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.util.List;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 1/3/2023 2:36 PM
 */
//@EnableFeignClients
public class SideCarConfiguration {

    @Bean
    public ServiceInfo serviceInfo(final Environment environment) {
        return new ServiceInfo(environment);
    }

    @Bean
    public ClientHelper clientHelper(@Autowired(required = false) PlatClient platClient) {
        ClientHelper clientHelper = new ClientHelper(platClient);
        ActionConsumer.setClientHelper(clientHelper);
        return clientHelper;
    }

    @Bean
    public BootstrapActionHelper bootstrapActionHelper(final List<ApplicationRegister> applicationRegister,
                                                       final ServiceInfo serviceInfo,
                                                       final ClientHelper clientHelper) {
        return new BootstrapActionHelper(applicationRegister, serviceInfo, clientHelper);
    }
}
